package com.infore.dataAudit.repository;


import java.util.List;
import java.util.Map;

import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.infore.dataAudit.entity.TDataAuditRecord;

public interface ITDataAuditRecordRepository extends JpaRepository<TDataAuditRecord, String>,
            JpaSpecificationExecutor<TDataAuditRecord>{
    
    /**
     * 查询审核记录根据某一流程 按审核时间降序
     * 
     * @author 蔡永顺
     * @return List<TDataAuditRecord>
     * @param flowId
     * @return
     * @date 2019年4月20日上午11:03:07
     */
    List<TDataAuditRecord> findByFlowInstanceIdOrderByAuditDateDesc(String flowId);
    
    @Query(value="SELECT * from (\r\n" + 
            "SELECT TO_CHAR(AUDIT_DATE,'yyyy-mm-dd hh24:mi:ss')AUDIT_DATE,AUDIT_USER,AUDIT_OPERATION,AUDIT_REASON from T_DATA_AUDIT_RECORD where FLOW_INSTANCE_ID = :flowId " + 
            "UNION ALL " + 
            "SELECT TO_CHAR(AUDIT_DATE,'yyyy-mm-dd hh24:mi:ss')AUDIT_DATE,AUDIT_USER,AUDIT_OPERATION, \"CONCAT\"(PROJ_NAME, AUDIT_REASON)AUDIT_REASON  from T_DATA_AUDIT_SIGN_RECORD where FLOW_INSTANCE_ID = :flowId " + 
            ") ORDER BY AUDIT_DATE DESC",nativeQuery=true)
    public List<Map<String,Object>> queryAuditOperaRecordByFlow(@Param("flowId")String flowId );

}
